
// export const baseUrl = "http://localhost:8090/";   //测试 https://jifugou.picp.vip  http://localhost:8090/  https://localhost/mms-mobile/
// export const baseUrl = "https://demo.sxpcwlkj.com/mms-mobile/"
export const baseUrl = "https://demo.sxpcwlkj.com/mms-mobile/"
export const configInfo ={
	"name":"集福购",
	"logo":"https://jifugou.oss-cn-zhangjiakou.aliyuncs.com/01_default/logo.png",
	"desc":"专注新零售店铺商品展示运营使用！",
	"qqmapsdk-key":"TDXBZ-ELKYX-OQJ4D-ZTJ4V-K7CR5-TLFN7"
}

export const userInfo = uni.getStorageSync('userInfo') || {
	"id":undefined,
	"nick": "",
	"score": 0,
	"memberPhone": "",
	"memberRandom": "",
	"inviteCode": "000000",
	"memberHeadimg": "",
	"state": 0,
	"type": 0,
	"memberId": 0
};
//多功能路由
const isClick = function(item) {
	// {type:1,url:'https://wwwe.sxpcwlkj.com'}
	// type=1 (普通页面)，type=2 (tabBar页面)，type=3 (openAppURL)，type=4  (weburl)
	// console.log(JSON.stringify(item));
	if (item.type == 1) {
		//商品链接
		let Url = item.url;
		let title = '';
		uni.navigateTo({
			url: Url,
			animationType: 'none',
			animationDuration: 500
		});
	} else if (item.type == 2) {
		//tabBar 页面
		let Url = item.url;
		uni.switchTab({
			url: Url
		});
	} else if (item.type == 3) {
		//openURL
		var urls = item.url;
		plus.runtime.openURL(encodeURI(urls));
	} else if (item.type == 4) {
		//webview
		var urls = item.url;
		uni.navigateTo({
			url: '/pages/webview/webview?url=' + urls
		});
	} else if (item.type == 5) {
		//redirectTo
		var urls = item.url;
		uni.redirectTo({
			url: urls,
			animationType: 'zoom-out',
			animationDuration: 500
		});
	}
}
// msg提示
const msg = (title, duration = 1500, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}
// 打印格式化
const jslog = (title, object) => {
	if (Boolean(title) === false || Boolean(object) === false) {
		return;
	}
	console.log("【打印】:" + title + "=>", JSON.stringify(object));
}
// 缓存 保存
const setdata = (key, value) => {
	uni.setStorage({
		key: key,
		data: value
	});
}
// 缓存 取值
const getdata = (key) => {
	uni.getStorage({
		key: key,
		success: function(res) {
			return res.data;
		}
	});
}
// 数值处理
const changeMoney = (num) => {
	num=Number(num)
	if (Number(num) <= 1) return {
		num,
		unit: '元'
	};
	var moneyUnits = ["元", "万", "亿", "万亿"]
	var dividend = 10000;
	var curentNum = num;
	//转换数字
	var curentUnit = moneyUnits[0];
	//转换单位
	for (var i = 0; i < 4; i++) {
		curentUnit = moneyUnits[i]
		if (strNumSize(curentNum) < 5) {
			break;
		}
		curentNum = curentNum / dividend
	}
	var m = {
		num: 0,
		unit: ""
	}
	m.num = Number(curentNum).toFixed(2)
	m.unit = curentUnit;
	// console.log(JSON.stringify(m))
	//{"num":"950.00","unit":"万元"}
	return m;
}
const strNumSize=(tempNum) => {
	var stringNum = tempNum.toString()
	var index = stringNum.indexOf(".")
	var newNum = stringNum;
	if (index != -1) {
		newNum = stringNum.substring(0, index)
	}
	return newNum.length
}
//开始加载
const apiStart = ()=>{
	uni.showLoading({
	    title: '加载中...'
	});
}
//结束加载
const apiStop = ()=>{
	uni.hideLoading();
}
// 不为空  true  反之  false
const isEmpty=(content)=>{
   if(typeof content === "undefined" || content === null || content.trim() === ""){
	   return true;
   }
   return false;
}
// 手机号验证
const checkPhone = (phone) => {
	const regexPhone = /^1[3-9]\d{9}$/;
	if (regexPhone.test(phone)) {
		return true
	} else {
		return false
	}
}
// 身份证验证
const checkNumber = (number) =>{
	const regexCard = /^(^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}(\d|X|x)?$)$/;
	if(regexCard.test(this.selfInfo.card.title)){
		return true
	}else{
		return false
	}
}
// 时间戳转年月日
function timestampToDate(timestamp) {
    // 确保timestamp是数字
    if (typeof timestamp !== 'number') {
        throw new Error('Timestamp must be a number');
    }

    // 创建一个新的Date对象，并传入时间戳（注意：JavaScript的Date对象是以毫秒为单位的，所以需要将秒转换为毫秒）
    var date = new Date(timestamp * 1000);

    // 你可以根据需要格式化日期
    var year = date.getFullYear();
    var month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份是从0开始的，所以需要+1，并且可能需要补0
    var day = ('0' + date.getDate()).slice(-2); // 可能需要补0

    // 返回格式化后的日期字符串
    return year + '-' + month + '-' + day
}
export const utils ={
	baseUrl,
	configInfo,
	userInfo,
	isClick,
	msg,
	jslog,
	setdata,
	getdata,
	changeMoney,
	apiStart,
	apiStop,
	isEmpty,
	checkPhone,
	checkNumber,
	timestampToDate
}
